import random
def load(a) :#装弹单独一个函数
    List = []
    Len = 0
    if a == 1:
        List.clear()
        Len = random.randint(3,10)
        for i in range(Len):
            List.append(random.randint(0,1))
        return List
    else :
        print('tap 1 if you are ready')
        
A=int(input('ready to gamble? tap 1 to continue'))
Box=load(A)

print('{} live round and {} blank'.format(Box.count(1),Box.count(0)))
print( 'player first' )

def round(box):
    Playerlife =  2 
    Demonlife = 2 
    r=0#加载生命值，射击界面，判定虚实存储变量
    Trans=0#转换射击权判定，0为不转换
    def PlayerRound(playerlife,demonlife,trans) :
        c = int(input('tap 2 to shoot your oppo'))
        if c == 2:
            r=box[0]
            box.pop(0)
            if r == 1 :
                print('Demon shot!')
                demonlife = demonlife -1
            else:
                print('blank')
            trans = 1
        else:
            r=box[0]
            box.pop(0)
            if r == 1 :
                print('Player shot!')
                playerlife = playerlife -1
            else:
                print('blank')
            trans = 0
        return playerlife, demonlife , trans
    def DemonRound(playerlife , demonlife , trans) :
        c = random.randint(2,3)#shoot the player or himself
        if c == 2:
            r=box[0]
            box.pop(0)
            if r == 1 :
                print('Player shot!')
                playerlife = playerlife -1
            else:
                print('blank')
            trans = 1
        else:
            r=box[0]
            box.pop(0)
            if r == 1 :
                print('Demon shot!')
                demonlife = demonlife -1
            else:
                print('blank')
            trans = 0
        return playerlife, demonlife , trans
    CurrentFunction = PlayerRound
    while Playerlife*Demonlife != 0:
        if Trans == 1:
            print('Gun transitted')
            CurrentFunction = DemonRound if CurrentFunction == PlayerRound else DemonRound
        else:
            print('Gun still')
            CurrentFunction = PlayerRound if CurrentFunction == PlayerRound else DemonRound
        Playerlife, Demonlife, Trans= CurrentFunction(Playerlife, Demonlife, Trans)
        print('玩家生命{}，恶魔生命{}'.format(Playerlife,Demonlife))

round(Box)